Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.pacist.diamonds.Splitter

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--com.pacist.diamonds.Splitter

public class Splitter
extends java.awt.Panel
implements java.awt.LayoutManager2, java.awt.event.MouseListener, java.awt.event.MouseMotionListener
Implements a layout manager that allows its components to be placed in rows and columns. The size of each row or column can be adjusted dynamically by clicking on the divider and dragging the divider to the desired position.

See Also:
Serialized Form

Field Summary
static int HORIZONTAL
          Used to specify a HORIZONTAL split.
static int VERTICAL
          Used to specify a VERTICAL split.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
Splitter()
          Default Constructor, Creates a Splitter with 1 row, 2 columns and divider width of 5 pixels.
Splitter(int rows, int cols, int hGap, int vGap, int defWidth, int defHeight, int margin, boolean shadowed)
          Constructor, Creates a Splitter using the specified values.
Splitter(int rows, int cols, int hGap, int vGap, int defWidth, int defHeight, int margin)
          Creates a Splitter using the specified parameters.
Splitter(int rows, int cols)
          Constructor, Creates a Splitter using the specified parameters.
Splitter(int rows, int cols, boolean shadowed)
          Constructor, Creates a Splitter using the parameters.
 
Method Summary
void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)
          Adds the specified component to the layout, using the specified constraint object.
void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          Adds the specified named component to the layout.
int colSpaceLeft()
          Calculates total space needed by components in a row
int dividerPos(int[] a, int x, int gap)
          Calculates the position of the feedback divider during drag.
void drawDivider()
          Draws the line that is a feedback to the user when resizing a row or a column
void drawLineInChildren(int x, int y, java.awt.Component[] c)
          Draws the line in the components as well.
int findDivider(int[] a, int x, int gap)
          Detects whether the user has clicked on a divider
int getCols()
          Returns the number of columns.
int getColWidth(int column)
          Gets the width of one column.
boolean[] getFillCols()
          Gets which columns will size proportionally to the size of the container.
boolean[] getFillRows()
          Gets which rows will size proportionally to the size of the container.
int getHGap()
          Returns the value of the height of the horizontal dividers.
float getLayoutAlignmentX(java.awt.Container parent)
          Returns the alignment along the x axis.
float getLayoutAlignmentY(java.awt.Container parent)
          Returns the alignment along the y axis.
int getRowHeight(int row)
          Gets the height of one row.
int getRows()
          Returns the number of rows.
int getVGap()
          Returns the value of the width of the vertical dividers.
void invalidateLayout(java.awt.Container target)
          Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
void layoutContainer(java.awt.Container target)
          Lays out the specified container.
java.awt.Dimension maximumLayoutSize(java.awt.Container target)
          Returns the maximum dimensions for this layout given the components in the specified target container.
java.awt.Dimension minimumLayoutSize(java.awt.Container target)
          Returns the minimum dimensions needed to layout the components contained in the specified target container.
void mouseClicked(java.awt.event.MouseEvent e)
           
void mouseDragged(java.awt.event.MouseEvent e)
          Drags the divider...
void mouseEntered(java.awt.event.MouseEvent e)
          Sets the cursor back to default when the mouse enters a child component.
void mouseExited(java.awt.event.MouseEvent e)
          Sets the cursor back to default when the Splitter loses focus.
void mouseMoved(java.awt.event.MouseEvent e)
          Decides if the mouse is on a divider to change to cursor to indicate to the user that the divider can be moved.
void mousePressed(java.awt.event.MouseEvent e)
          Sets up the environment for dragging a divider.
void mouseReleased(java.awt.event.MouseEvent e)
          Locates the position of the divider and forces the window to display the change.
void paint(java.awt.Graphics g)
          Redraws the Splitter on the window.
java.awt.Dimension preferredLayoutSize(java.awt.Container target)
          Returns the preferred dimensions for this layout given the components in the specified target container.
void removeLayoutComponent(java.awt.Component comp)
          Removes the specified component from the layout.
int rowSpaceLeft()
          Calculates total space needed by components in a column
void setCols(int col)
          Reformats the Splitter to contain the number of specified columns.
void setColWidth(int column, int width)
          Sets the width of one column.
void setFillCols(boolean[] fillCols)
          Sets which columns will size proportionally to the size of the container.
void setFillRows(boolean[] fillRows)
          Sets which rows will size proportionally to the size of the container.
void setHGap(int val)
          Modifies the height of the horizontal dividers.
void setRowHeight(int row, int height)
          Sets the height of one row.
void setRowsAndCols(int row, int col)
          Reformats the Splitter to contain the number of specified rows and columns.
void setRows(int row)
          Reformats the Splitter to contain the number of specified rows.
void setVGap(int val)
          Modifies the width of the vertical dividers.
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponentAt, getComponentAt, getComponent, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paint, paramString, preferredSize, printComponents, print, processContainerEvent, processEvent, removeAll, remove, remove, removeContainerListener, removeNotify, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paint, paramString, postEvent, preferredSize, prepareImage, prepareImage, printAll, print, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

HORIZONTAL

public static final int HORIZONTAL
Used to specify a HORIZONTAL split.

VERTICAL

public static final int VERTICAL
Used to specify a VERTICAL split.
Constructor Detail

Splitter

public Splitter()
Default Constructor, Creates a Splitter with 1 row, 2 columns and divider width of 5 pixels.

Splitter

public Splitter(int rows,
                int cols,
                int hGap,
                int vGap,
                int defWidth,
                int defHeight,
                int margin,
                boolean shadowed)
Constructor, Creates a Splitter using the specified values.
Parameters:
rows - number of rows in the Splitter.
cols - number of columns in the Splitter.
hGap - horizontal gap between each component.
vGap - vertical gap between each component.
defWidth - default width of each component.
defHeight - default height of each component.
margin - border margin.
shadowed - draw (or don't draw) a shadow showing where the draggable divider is.

Splitter

public Splitter(int rows,
                int cols,
                int hGap,
                int vGap,
                int defWidth,
                int defHeight,
                int margin)
Creates a Splitter using the specified parameters.
Parameters:
rows - number of rows in the Splitter.
cols - number of columns in the Splitter.
hGap - horizontal gap between each component.
vGap - vertical gap between each component.
defWidth - default width of each component.
defHeight - default height of each component.
margin - border margin.

Splitter

public Splitter(int rows,
                int cols)
Constructor, Creates a Splitter using the specified parameters.
Parameters:
rows - number of rows in the Splitter.
cols - number of columns in the Splitter.

Splitter

public Splitter(int rows,
                int cols,
                boolean shadowed)
Constructor, Creates a Splitter using the parameters.
Parameters:
rows - number of rows in the Splitter.
cols - number of columns in the Splitter.
shadowed - draw (or don't draw) a shadow showing where the draggable divider is.
Method Detail

setRows

public void setRows(int row)
Reformats the Splitter to contain the number of specified rows.
Parameters:
row - number of rows in the Splitter.

setRowHeight

public void setRowHeight(int row,
                         int height)
Sets the height of one row. If the row number passed in is less than zero or greater than the number of rows, then an ArrayIndexOutOfBoundsException is thrown
Parameters:
row - the row to adjust.
height - the new height.

getRowHeight

public int getRowHeight(int row)
Gets the height of one row. If the row number passed in is less than zero or greater than the number of rows, then an ArrayIndexOutOfBoundsException is thrown
Parameters:
row - the specified row.

setColWidth

public void setColWidth(int column,
                        int width)
Sets the width of one column. If the column number passed in is less than zero or greater than the number of column, then an ArrayIndexOutOfBoundsException is thrown
Parameters:
column - the column to adjust.
width - the new width.

getColWidth

public int getColWidth(int column)
Gets the width of one column. If the column number passed in is less than zero or greater than the number of column, then an ArrayIndexOutOfBoundsException is thrown
Parameters:
column - the specified column.

getRows

public int getRows()
Returns the number of rows.
Returns:
int - number of rows in the Splitter.

setCols

public void setCols(int col)
Reformats the Splitter to contain the number of specified columns.
Parameters:
col - number of columns in the Splitter.

getCols

public int getCols()
Returns the number of columns.
Returns:
int - number of rows in the Splitter.

setRowsAndCols

public void setRowsAndCols(int row,
                           int col)
Reformats the Splitter to contain the number of specified rows and columns.
Parameters:
row - number of rows in the Splitter.
col - number of columns in the Splitter.

setFillRows

public void setFillRows(boolean[] fillRows)
Sets which rows will size proportionally to the size of the container.
Parameters:
fillRows - which rows will be proportional.

getFillRows

public boolean[] getFillRows()
Gets which rows will size proportionally to the size of the container.
Returns:
boolean[] - array of 'growing' rows.

setFillCols

public void setFillCols(boolean[] fillCols)
Sets which columns will size proportionally to the size of the container.
Parameters:
fillCols - which columns will be proportional.

getFillCols

public boolean[] getFillCols()
Gets which columns will size proportionally to the size of the container.
Returns:
boolean[] - array of 'growing' columns.

setHGap

public void setHGap(int val)
Modifies the height of the horizontal dividers.
Parameters:
val - height of the divider.

setVGap

public void setVGap(int val)
Modifies the width of the vertical dividers.
Parameters:
val - width of the divider.

getVGap

public int getVGap()
Returns the value of the width of the vertical dividers.
Returns:
int - width of the divider.

getHGap

public int getHGap()
Returns the value of the height of the horizontal dividers.
Returns:
int - height of the divider.

paint

public void paint(java.awt.Graphics g)
Redraws the Splitter on the window.
Parameters:
g - the graphics context.
Overrides:
paint in class java.awt.Container

drawDivider

protected void drawDivider()
Draws the line that is a feedback to the user when resizing a row or a column

drawLineInChildren

protected void drawLineInChildren(int x,
                                  int y,
                                  java.awt.Component[] c)
Draws the line in the components as well.
Parameters:
x - the x co-ordinate.
y - the y co-ordinate.
c - array of all child components.

findDivider

protected int findDivider(int[] a,
                          int x,
                          int gap)
Detects whether the user has clicked on a divider
Parameters:
a - array of element width/height.
x - location where mouse has been clicked (x if checking for rows, y if checking for columns).
gap - space between each component i.e. width/height of dividers.
Returns:
int - -1 if it could not find row or column; otherwise row or column number.

dividerPos

protected int dividerPos(int[] a,
                         int x,
                         int gap)
Calculates the position of the feedback divider during drag.
Parameters:
a - array of element width/height.
x - row/column number of the dragged divider.
gap - space between each component i.e. width/height of dividers.
Returns:
int x/y coordinate of where to draw the divider.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Sets up the environment for dragging a divider.
Specified by:
mousePressed(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - co-ordinate details of where the mouse was pressed.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Drags the divider...
Specified by:
mouseDragged(java.awt.event.MouseEvent) in interface java.awt.event.MouseMotionListener
Parameters:
e - co-ordinate details of where the mouse was dragged.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Locates the position of the divider and forces the window to display the change.
Specified by:
mouseReleased(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - co-ordinate details of where the mouse was released.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Decides if the mouse is on a divider to change to cursor to indicate to the user that the divider can be moved.
Specified by:
mouseMoved(java.awt.event.MouseEvent) in interface java.awt.event.MouseMotionListener
Parameters:
e - details of where the mouse was moved.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Sets the cursor back to default when the Splitter loses focus.
Specified by:
mouseExited(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - mouse event details.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Sets the cursor back to default when the mouse enters a child component.
Specified by:
mouseEntered(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener
Parameters:
e - the mouse event.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Description copied from interface:
 
Specified by:
mouseClicked(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener

addLayoutComponent

public void addLayoutComponent(java.awt.Component comp,
                               java.lang.Object constraints)
Adds the specified component to the layout, using the specified constraint object.
Specified by:
addLayoutComponent(java.awt.Component, java.lang.Object) in interface java.awt.LayoutManager2
Parameters:
comp - the component to be added.
constraints - where/how the component is added to the layout.

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Adds the specified named component to the layout.
Parameters:
name - the String name.
comp - the component to be added.

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Removes the specified component from the layout.
Parameters:
comp - the component to be removed.

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container target)
Returns the minimum dimensions needed to layout the components contained in the specified target container.
Parameters:
target - the Container on which to do the layout.
Returns:
Dimension - the minimum layout size.

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container target)
Returns the preferred dimensions for this layout given the components in the specified target container.
Parameters:
target - the component which needs to be laid out.
Returns:
Dimension - the preferred layout size.

maximumLayoutSize

public java.awt.Dimension maximumLayoutSize(java.awt.Container target)
Returns the maximum dimensions for this layout given the components in the specified target container.
Specified by:
maximumLayoutSize(java.awt.Container) in interface java.awt.LayoutManager2
Parameters:
target - the component which needs to be laid out.
Returns:
Dimension - the maximum layout size.

getLayoutAlignmentX

public float getLayoutAlignmentX(java.awt.Container parent)
Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
Specified by:
getLayoutAlignmentX(java.awt.Container) in interface java.awt.LayoutManager2
Returns:
float - the alignment.

getLayoutAlignmentY

public float getLayoutAlignmentY(java.awt.Container parent)
Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
Specified by:
getLayoutAlignmentY(java.awt.Container) in interface java.awt.LayoutManager2
Returns:
float - the alignment.

invalidateLayout

public void invalidateLayout(java.awt.Container target)
Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
Specified by:
invalidateLayout(java.awt.Container) in interface java.awt.LayoutManager2

colSpaceLeft

public int colSpaceLeft()
Calculates total space needed by components in a row
Returns:
int - space left.

rowSpaceLeft

public int rowSpaceLeft()
Calculates total space needed by components in a column
Returns:
int - space left.

layoutContainer

public void layoutContainer(java.awt.Container target)
Lays out the specified container. Calculates the width and height of each row and column.
Parameters:
target - the component being laid out.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD